package org.duiduo.factory;

import lombok.extern.slf4j.Slf4j;
import org.duiduo.enums.UserRequestEnum;
import org.duiduo.service.TbUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 用户 工厂
 *
 * @author 夜泷noga
 */
@Slf4j
@Component
public class TbUserServiceFactory {

    @Resource(name = "TbUserServiceImpl")
    private TbUserService userServiceImpl;

    @Resource(name = "CacheTbUserServiceImpl")
    private TbUserService cacheUserServiceImpl;

    public TbUserService getUserServiceImpl(Integer userRequestType) {
        if (UserRequestEnum.USER_REQUEST_TYPE_NOMAL.getUserRequestType().equals(userRequestType)) {
            log.info("用户请求类型:{}", UserRequestEnum.USER_REQUEST_TYPE_NOMAL.getUserRequestTypeName());
            return userServiceImpl;
        }
        if (UserRequestEnum.USER_REQUEST_TYPE_CACHE.getUserRequestType().equals(userRequestType)) {
            log.info("用户请求类型:{}", UserRequestEnum.USER_REQUEST_TYPE_CACHE.getUserRequestTypeName());
            return cacheUserServiceImpl;
        }
        log.info("用户请求类型:{}", userRequestType);
        return null;
    }
}
